package com.atguigu.dga.governance.assessor.calc;

import com.atguigu.dga.ds.bean.TDsTaskInstance;
import com.atguigu.dga.governance.assessor.Assessor;
import com.atguigu.dga.governance.bean.AssessParam;
import com.atguigu.dga.governance.bean.GovernanceAssessDetail;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

@Component("IS_TASK_FAILED")
public class IsTaskFailedAssessor extends Assessor {
    @Override
    public void checkProblem(AssessParam assessParam, GovernanceAssessDetail governanceAssessDetail) throws ParseException {
        if(assessParam.getTDsTaskInstanceList()==null){
            return;
        }
        List<TDsTaskInstance> tDsTaskInstanceList = assessParam.getTDsTaskInstanceList();
        for (TDsTaskInstance tDsTaskInstance : tDsTaskInstanceList) {
            Date submitTime = tDsTaskInstance.getSubmitTime();
            String submitDt = DateFormatUtils.format(submitTime, "yyyy-MM-dd");

            if (tDsTaskInstance.getState() == 6 && assessParam.getAssessDate().equals(submitDt)) {
                governanceAssessDetail.setAssessScore(BigDecimal.ZERO);
                governanceAssessDetail.setAssessProblem("存在任务失败");
                return;
            }
        }
    }
}
